class Registerqy {
    constructor() {
        console.log(1);
        this.init();
    }
}
$.extend(Registerqy.prototype, {
    init: function () {
        $('.getCap').on('click', $.proxy(this.getCap, this));
        $('.nowSubmit').on('click', $.proxy(this.submit, this));
    },
    submit: function () {
        let username = $('.username').val();
        let password = $('.password').val();
        let repassword = $('.repassword').val();
        let tel = $('.tel').val();
        let captcha = $('.captcha').val();
        console.log(username,password,tel,captcha)
        if (password !== repassword) {
            alert('两次密码不一致，请重试');
        }
        else if (tel === '' || username === '' || captcha === "" || password === "") {
            alert('客观请您先把信息填完整好不好，嘤嘤嘤');
        }
        else {
            $.ajax({
                url: 'http://localhost:8888/qy', data: {
                    username: username,
                    password: password,
                    tel: tel,
                    captcha: captcha
                }, success: function (res) {
                    console.log(res);

                    switch (res) {
                        case '0': alert('本电话已经呗注册了，你想想接下来怎么办吧，嘤嘤嘤'); break;
                        case '1': alert('注册成功，厉害了您， 佩服得只剩嘤嘤嘤了'); break;
                    }
                }
            });
        }



    },
    getCap: function () {
        let num = this.random();
        $('.captcha').val(num);
    },
    random: function () {
        let a = parseInt(Math.random() * 10);
        let b = parseInt(Math.random() * 10);
        let c = parseInt(Math.random() * 10);
        let d = parseInt(Math.random() * 10);
        let num = '' + a + b + c + d;
        return num;
    }
});
new Registerqy();